#位置参数,用来占位的
#计算2的6次方,其中x和n就是位置参数
def power(x,n):
    s =1
    while n > 0:
        n = n - 1
        s = s * x
    return s
print(power(2,6))

#默认参数(必选参数在前，默认参数在后),就是在定义函数的时候，给参数指定默认值，在函数调用的时候
#如果不输出次参数，则用默认值，否则使用给定的参数
def power(x,n=5):
    s =1
    while n > 0:
        n = n - 1
        s = s * x
    return s
print(power(2))
print(power(2,6))

def enroll(name,gender,age=6,city='ShangHai'):
    print('name =',name)
    print('gender =',gender)
    print('age =',age)
    print('city =',city)
enroll('zhangsan','男')
enroll('zhangsan','男',age=22)
enroll('zhangsan','男',city='Beijing')

def add_end(L=None):
    if L is None:
        L =[]
    L.append('END')
    return L
    
print(add_end([1,2,3]))
print(add_end())
print(add_end())

#可变参数：传入的参数个数是可变的
#特点：可变参数允许你传入0个或任意个参数，这些可变参数在函数调用时自动组装为一个tuple
def calc(numbers):
    sum = 0
    for n in numbers:
        sum = sum + n * n
    return sum
#print(calc([1,2,3]))
#print(calc((1,2,3)))

#改写成可变参数,在参数前面加*号
def calc(*numbers):
    sum = 0
    for n in numbers:
        sum = sum + n * n
    return sum
#接收单个参数
print(calc(1,2,3,4))
print(calc(1,2,3))
#接收list or tuple，在定义好的list或者tuple前加*号
a = [2,4,6]
print(calc(*a))




